local skel = fk.CreateSkill{
  name = "kqf__xiyin",
}

local DIY = require "packages/diy_utility/diy_utility"

Fk:loadTranslationTable{
  ["kqf__xiyin"] = "希音",
  [":kqf__xiyin"] = "你可以重铸一至四张牌并视为使用或打出【杀】/【闪】；然后若本回合弃牌堆中的牌未包含所有花色，你不能再以此法重铸此量张牌。",

  ["#kqf__xiyin_ask"] = "希音：你可以重铸一至四张牌并视为使用或打出【杀】/【闪】；<br>然后若本回合弃牌堆中的牌未包含所有花色，你不能再以此法重铸此量张牌。",
  ["@kqf__xiyin"] = "希音：",

  ["$kqf__xiyin1"] = "二子不可兼顾，妾身唯保其一。",
  ["$kqf__xiyin2"] = "吾子虽弃亦可，前遗万勿有失。",
}

skel:addAcquireEffect(function (self, player, is_start)--DIYU的中央区加入游戏
  player.room:addSkill("#CenterArea")
end)

skel:addEffect("viewas", {
  pattern = "slash,jink",
  prompt = "#kqf__xiyin_ask",
  card_filter = function(self, player, to_select, selected)
    return #selected < 4 and table.contains(player:getCardIds("he"), to_select)
  end,
  interaction = function(self, player)
    local names = player:getViewAsCardNames(skel.name, {"slash", "jink"})
    return UI.CardNameBox {choices = names, all_choices = {"slash", "jink"}}
  end,
  view_as = function(self, player, cards)
    local marks = player:getTableMark("@kqf__xiyin")
    if #cards == 0 then return end
    if #marks > 0 then
      if #cards == 1 and table.contains(marks,"1") then return end
      if #cards == 2 and table.contains(marks,"2") then return end
      if #cards == 3 and table.contains(marks,"3") then return end
      if #cards == 4 and table.contains(marks,"4") then return end
    end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = skel.name
    card:addFakeSubcards(cards)
    return card
  end,
  before_use = function(self, player, use)
    local cards = use.card.fake_subcards
    player.room:recastCard(cards,player,skel.name)
  end,
  after_use = function (self, player, use)
    local cards = DIY.getCenterCards(player.room)
    if table.find(cards,function (c) return Fk:getCardById(c).suit == Card.Spade end) then
      if table.find(cards,function (c) return Fk:getCardById(c).suit == Card.Club end) then
        if table.find(cards,function (c) return Fk:getCardById(c).suit == Card.Heart end) then
          if table.find(cards,function (c) return Fk:getCardById(c).suit == Card.Club end) then
            return
          end
        end
      end
    end
    local cardslen = #use.card.fake_subcards
    player.room:addTableMarkIfNeed(player, "@kqf__xiyin", tostring(cardslen))
  end,
  enabled_at_response = function(self, player, response)
    return not player:isNude()
  end,
})


return skel